package com.bilicraft;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.util.regex.*;
import javax.swing.JFrame;
import res.Resources;


public class Launcher extends JFrame {
	
	public GraphicsEnvironment GE;
	public GraphicsDevice GD;
	public DisplayMode DM;
	
	public PanelLogin loginPanel;
	public FileOps fileOps;
	public Resources res;
	public FrameConfig configFrame;
	public FrameUpdate updateFrame;
	
	public String username = "";
	public int memSize = 1024;
	public boolean d64 = false;
	public String pathHome = System.getProperty("java.home")+"\\bin";
	public String version = "20120829";
	public Version ver;
	
	
	
	private static final long serialVersionUID = 1L;
	
	
	public Launcher(){
		
		fileOps = new FileOps();
		
		try{
			String s1 = fileOps.read();
			try{
			String[] s2;
			s2 = s1.split(" ");
			System.out.println(s2[3]);
			System.out.println(s2.length);
			username = s2[s2.length-1];
			if(s2.length == 12){
				d64 = true;
				System.out.println("64-bits.");
			}else{
				d64 = false;
			}
			String[] ss3 = fileOps.cmdsPath.split("\"");
			pathHome = ss3[1];
			Pattern pattern = Pattern.compile("\\d+");   
		       Matcher matcher = pattern.matcher(s2[5]);   
		       if (matcher.find()) {   
		    	   String s3 = matcher.group(0);
		           System.out.println(s3);
		           int a = Integer.parseInt(s3);
		           System.out.println(a);
		           memSize = a;
		       }   
			}catch(Exception e){
				System.err.println(e.toString());
			}
		}catch(IOException ie){
			System.err.println(ie.toString());
		}
		
		
		
		GE = GraphicsEnvironment.getLocalGraphicsEnvironment(); 
		GD = GE.getDefaultScreenDevice();
		DM = GD.getDisplayMode();
		
		res = new Resources();
		
	    loginPanel = new PanelLogin(this);
	    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	    setSize(854, 480);
	    setIconImage(res.icon);
	    setTitle("BiliCraft");
	    //setResizable(false);
	    add(loginPanel);
	    loginPanel.setPreferredSize(new Dimension(854, 480));
	    addComponentListener(new MCA());
	    pack();
	    setLocation((DM.getWidth()-getWidth())/2, (DM.getHeight()-getHeight())/2);
	    
	    
	    setVisible(true);
	}
	
	class MCA extends ComponentAdapter {

        public void componentResized(ComponentEvent e) {
           if(loginPanel != null){
        	   loginPanel.repaint();
           }

       }

    }

	
	
	public static void main(String args[]){
		
		Launcher l = new Launcher();		
		l.ver = new Version(l);
	}
	

	
	
}
